package com.ruoyi.web.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MultipleChoiceQuestions;
import com.ruoyi.system.service.IMultipleChoiceQuestionsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 选择题管理Controller
 *
 * @author ruoyi
 * @date 2022-08-19
 */
@Controller
@RequestMapping("/system/questions")
public class MultipleChoiceQuestionsController extends BaseController {
    private String prefix = "system/questions";

    @Autowired
    private IMultipleChoiceQuestionsService multipleChoiceQuestionsService;

    @RequiresPermissions("system:questions:view")
    @GetMapping()
    public String questions() {
        return prefix + "/questions";
    }

    /**
     * 查询选择题管理列表
     */
    @RequiresPermissions("system:questions:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MultipleChoiceQuestions multipleChoiceQuestions) {
        startPage();
        List<MultipleChoiceQuestions> list = multipleChoiceQuestionsService.selectMultipleChoiceQuestionsList(multipleChoiceQuestions);
        return getDataTable(list);
    }

    /**
     * 导出选择题管理列表
     */
    @RequiresPermissions("system:questions:export")
    @Log(title = "选择题管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MultipleChoiceQuestions multipleChoiceQuestions) {
        List<MultipleChoiceQuestions> list = multipleChoiceQuestionsService.selectMultipleChoiceQuestionsList(multipleChoiceQuestions);
        ExcelUtil<MultipleChoiceQuestions> util = new ExcelUtil<MultipleChoiceQuestions>(MultipleChoiceQuestions.class);
        return util.exportExcel(list, "选择题管理数据");
    }

    /**
     * 新增选择题管理
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存选择题管理
     */
    @RequiresPermissions("system:questions:add")
    @Log(title = "选择题管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MultipleChoiceQuestions multipleChoiceQuestions) {
        return toAjax(multipleChoiceQuestionsService.insertMultipleChoiceQuestions(multipleChoiceQuestions));
    }

    /**
     * 修改选择题管理
     */
    @RequiresPermissions("system:questions:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        MultipleChoiceQuestions multipleChoiceQuestions = multipleChoiceQuestionsService.selectMultipleChoiceQuestionsById(id);
        mmap.put("multipleChoiceQuestions", multipleChoiceQuestions);
        return prefix + "/edit";
    }

    /**
     * 修改保存选择题管理
     */
    @RequiresPermissions("system:questions:edit")
    @Log(title = "选择题管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MultipleChoiceQuestions multipleChoiceQuestions) {
        return toAjax(multipleChoiceQuestionsService.updateMultipleChoiceQuestions(multipleChoiceQuestions));
    }

    /**
     * 删除选择题管理
     */
    @RequiresPermissions("system:questions:remove")
    @Log(title = "选择题管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(multipleChoiceQuestionsService.deleteMultipleChoiceQuestionsByIds(ids));
    }


    @PostMapping("/mylist")
    @ResponseBody
    public AjaxResult MygetList(MultipleChoiceQuestions multipleChoiceQuestions) {
        List<MultipleChoiceQuestions> list = multipleChoiceQuestionsService.selectMultipleChoiceQuestionsList(multipleChoiceQuestions);
        return success(list);
    }


    @PostMapping("/getById")
    @ResponseBody
    public AjaxResult MygetById(@RequestParam("Id") Long id) {
        return success(multipleChoiceQuestionsService.selectMultipleChoiceQuestionsById(id));
    }


}
